package com.pacy.pacybaseproject.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.fondesa.recyclerviewdivider.DividerBuilder;
import com.gyf.immersionbar.ImmersionBar;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopupext.listener.TimePickerListener;
import com.lxj.xpopupext.popup.TimePickerPopup;
import com.pacy.pacybaseproject.BR;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.base.BaseXActivity;
import com.pacy.pacybaseproject.databinding.ActivityAllReceiveBinding;
import com.pacy.pacybaseproject.viewmodels.AllReceiveViewModel;

import java.util.Date;

import me.goldze.mvvmhabit.utils.DateUtil;
import me.goldze.mvvmhabit.views.StateLayout;

/**
 * 所有收益
 */
public class AllReceiveActivity extends BaseXActivity<ActivityAllReceiveBinding, AllReceiveViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_all_receive;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setToolbar(binding.baseToolBar);
        setStateLayout(binding.state);
//        binding.view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, BarUtils.getStatusBarHeight()));
        if (binding.recyclerView.getItemDecorationCount() == 0) {
            new DividerBuilder(AllReceiveActivity.this)
                    .size(10, TypedValue.COMPLEX_UNIT_DIP)
                    .color(Color.TRANSPARENT)
//                    .showFirstDivider()
//                    .showLastDivider()
                    .build().addTo(binding.recyclerView);
        }
        binding.selectTimeTv.setOnClickListener(v -> showDatePicker());

        binding.state.setOnEmptyRetryListener(new StateLayout.OnEmptyContentRetryListener() {
            @Override
            public void onEmptyContentRetry() {
            }
        });
    }


    /**
     * 日期选择器
     */
    private void showDatePicker() {
        TimePickerPopup popup = new TimePickerPopup(AllReceiveActivity.this)
                .setShowLabel(false)
                .setMode(TimePickerPopup.Mode.YM)
                .setTimePickerListener(new TimePickerListener() {
                    @Override
                    public void onTimeChanged(Date date) {
                        //时间改变
                    }
                    @Override
                    public void onTimeConfirm(Date date, View view) {
                        //点击确认时间
                        viewModel.occurTime.setValue(DateUtil.dateToString(date, DateUtil.DatePattern.ONLY_MONTH));
                    }

                    @Override
                    public void onCancel() {

                    }
                });

        new XPopup.Builder(AllReceiveActivity.this)
                .asCustom(popup)
                .show();
    }
}